﻿//Ninject
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Domain.Abstract;
using Domain.Concrete;
using Ninject;
using Moq;
using Domain.Entity;

namespace Pro260Website.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel _ninjectKernel;

        public NinjectControllerFactory()
        {
            _ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext,
            Type controllerType)
        {
            return controllerType == null ? null : (IController)_ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            var gameWithNews = new Game { Id = 12, Name = "Upcoming Game 4", Description = "Upcoming Game 4 -- has news :D", ReleaseDate = DateTime.Now.Add(new TimeSpan(24, 12, 3)) };
            gameWithNews.Articles.Add(new GameNewsArticle()
            {
                Id = 1,
                Title = "News Article 1",
                Abstract = "Article 1",
                Description = "The text of Article 1",
                PostedDate = new DateTime(),
                Game = gameWithNews
            });
            gameWithNews.Articles.Add(new GameNewsArticle()
            {
                Id = 2,
                Title = "News Article 2",
                Abstract = "Article 2",
                Description = "The text of Article 2",
                PostedDate = new DateTime(),
                Game = gameWithNews
            });

            var PCGame = new Game()
            {
                Id = 13,
                Name = "Digger",
                Genre = "Arcade",
                ContentRating = "E",
                ReleaseDate = new DateTime(1983, 1, 1),
                Description = "A fun platform with addicting music, enjoy your travels underground, dodging rocks and monsters while collecting coins."
            };
            PCGame.Platforms.Add(new Platform() { PlatformID = 1, Name = "PC" });
            PCGame.SystemRequirements = new SystemRequirements()
            {
                OS = "Windows 7",
                Memory = "2.0 GB",
                Processor = "1 kHz",
                VideoCard = "any bitmap compatible 5KB of VRAM"
            };


            this.AddRepositoryBindings();
           // _ninjectKernel.Bind<IAccountRepository>().To<EFAccountRepository>().InRequestScope();
            //ModelBinders.Binders.Add((typeof(Account)));
        }

        private void AddRepositoryBindings()
        {
            _ninjectKernel.Bind<IFeedbackRepository>().To<EFFeedbackRepository>();
            _ninjectKernel.Bind<IReviewRepository>().To<EFReviewRepository>();
            _ninjectKernel.Bind<ICompanyRepository>().To<EFCompanyRepository>();
            _ninjectKernel.Bind<IPlatformRepository>().To<EFPlatformRepository>();
            _ninjectKernel.Bind<IAccountRepository>().To<EFAccountRepository>();
            _ninjectKernel.Bind<IGameRepository>().To<EFGameRepository>();
            _ninjectKernel.Bind<IPictureRepository>().To<EFPictureRepository>();
            _ninjectKernel.Bind<IVideoRepository>().To<EFVideoRepository>();
            _ninjectKernel.Bind<IMetaScoreRepository>().To<EFMetaScoreRepository>();
        }
    }
}